<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
            思路：使用k个数，满足和为n。因为集合范围是[1,9]默认有序，且无重复数字，所以无需去重
            */
            var combinationSum3 = function (k, n) {
                let res = []
                function backTracking(path, sum, start) {
                    if (sum == n && path.length == k) {
                        return res.push([...path])
                    }
                    for (let i = start; i <= 9; i++) {
                        path.push(i)
                        backTracking(path, sum + i, i + 1)
                        path.pop()
                    }
                }
                backTracking([], 0, 1)
                return res
            }
        </script>
    </body>
</html>
